/**
 * Definition for a binary tree node.
 * struct TreeNode {
 *     int val;
 *     TreeNode *left;
 *     TreeNode *right;
 *     TreeNode(int x) : val(x), left(NULL), right(NULL) {}
 * };
 */
class Solution {
public:
    int treeDepth(TreeNode* root) {
        int ans=0;
        queue<TreeNode*> q;
        if(root) q.push(root);
        while(!q.empty())
        {
            ans++;
            int sz=q.size(); //计算该层有多少节点
            while(sz--)
            {
                auto u=q.front(); q.pop();
                if(u->left) q.push(u->left);
                if(u->right) q.push(u->right);
            }
        }
        return ans;
    }
};